clc
clear all
close all


%i = 1

visualizacao = true
nimg = 10;
grao = 'P1500' 
pds = [' a';' b';' c';' d';' e';' f';' g';' h';' i';' j';' l';' m';' n';' o';' p'];
spc = [' aa';' bb';' cc';' dd';' ee';' ff';' gg';' hh';' ii';' jj';' ll';' mm';' nn';' oo';' pp'];


%spc = ['ar';'br';'cr';'dr';'er';'fr';'gr';'hr';'jr';'lr';'mr';'nr';'or';'pr'];~
%fgs = ['FG1';'FG2';'FG3';'FG4';'FG5';'FG6';'FG7';'FG8';'FG9'];

    figure(1)

    set(1,'Position',[24 51 1232 650])
    set(1,'NumberTitle','off')
    set(1,'Name','Análise Spectral')

    fn = ['C:\Programas\MATLAB71\work\Ensaios Mestrado - 05.05.08\Imagens 2ºparte Trabalho\22.01.09 - Testes\253FA 3M Tirzact']
    
    irgb = imread(fn);
    icinz = rgb2gray(irgb);
    th = graythresh(icinz);

    step=1;
    ireduzida=icinz(1:step:size(icinz,1), 1:step:size(icinz,2));
    se = strel('square',10);

    ivalmax = imtophat(ireduzida,se);
    iajust = imadjust(ivalmax,[0 0.5],[]);

    h = imhist(iajust);
    ibin = im2bw(iajust,th);

     
    [v,unv] = statmoments(h, 2);
    
    padrao(ct1).media = v(1);
    padrao(ct1).desvio = v(2);
    padrao(ct1).mediaun = unv(1);
    padrao(ct1).desvioun = unv(2);
    mediaplot(ct1) = v(1);
    desvplot(ct1)= v(2);
    
    rst(ct1,:)= statxture(iajust);
    
    [labeled,numGant] = bwlabel(ibin,4);
    figure(5)
    imshow(ibin)

    figure(1),
    
    subplot(2,3,1)
    imshow(icinz),
    title('rgb2gray')
    
    figure(1),
    subplot(2,3,2)
    imshow(iajust),
    title('imadjust')
    
    figure(1),
    subplot(2,3,3)
    imshow(ibin),
    title('im2bw')
    
    [srad, sang, S]=specxture(iajust);
    figure(1),
    subplot(2,3,4)
    plot(srad), 
    title('srad')
    
    figure(1),
    subplot(2,3,5)
    plot(sang), 
    title('sang')
    
    figure(1),
    subplot(2,3,6)
    imshow(S),
    title('Spectrum Image')
    
        